import { NextResponse } from 'next/server'; import { adminApi, AdminApiError } from '@/lib/admin-api'; import { isAdmin } from '@/lib/admin-auth'; export const dynamic = 'force-dynamic'; /** Queue a manual connector run (proxied to FastAPI with the server-side token). Requires the admin session cookie. */ export async function POST(_req: Request, ctx: { params: Promise<{ name: string }> }): Promise { if (!(await isAdmin())) return NextResponse.json({ error: { title: 'Unauthorized', status: 401 } }, { status: 401 }); const { name } = await ctx.params; try { const out = await adminApi.triggerRun(name); return NextResponse.json(out.data); } catch (e) { const status = e instanceof AdminApiError && e.status > 0 ? e.status : 502; return NextResponse.json({ error: { title: 'Run request failed', detail: (e as Error).message, status } }, { status }); } }